package com.k1998.mybatis.controller;

import com.k1998.mybatis.bean.User;

import com.k1998.mybatis.dao.IUserDao;
import com.k1998.mybatis.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private IUserDao iUserDao;

    @RequestMapping("/find_all")
    public List<User>  getAll() {
        List<User> users = iUserDao.findAll();
        return users;
    }

    @RequestMapping("/save")
    public ResponseEntity<Result> save(@RequestBody String json) {
        Result res = new Result(200, "创建成功");
        System.out.println(res);

        Map<String, Object> data = new HashMap<String, Object>();
        User user = iUserDao.findById(1);
        data.put("p1",user);
        res.setData(data);

        System.out.println(data);
        return ResponseEntity.ok(res);
    }




//    @RequestMapping("/list")
//    public String list(@RequestBody String json) throws Exception {
//        List<User> users = iUserDao.findAll();
//
//        return MyResultUtils.getSuccess(users,"删除");
//    }

}
